Cover | TOC | Chap | Prev Chap | Prev Fig | Next Fig | Next Chap |
![]() |
Figure 30.3
A pair of filters used to create a momentary on-off switch. |
|
Click on the image to view the VRML scene. |
#VRML V2.0 utf8 # The VRML 2.0 Sourcebook # Copyright (c) 1997 # Andrea L. Ames, David R. Nadeau, and John L. Moreland Group { children [ # Background Background { skyColor [ 1.0 0.0 0.0, 1.0 0.4 0.0, 1.0 1.0 0.0 ] skyAngle [ 1.309, 1.571 ] groundColor [ 0.1 0.1 0.0, 0.5 0.25 0.2, 0.6 0.6 0.2 ] groundAngle [ 1.309, 1.571 ] }, # On-off switch Shape { appearance Appearance { material Material { diffuseColor 1.0 0.3 0.3 } } geometry Sphere { } }, DEF Touch TouchSensor { }, # Sound Sound { source DEF Audio AudioClip { url "willow1.wav" loop TRUE stopTime 1.0 } }, # Filters DEF Filter Script { url "javascript: function set_boolean( bool, eventTime ) { if ( bool == true ) { true_changed = true; } else { false_changed = true; } }" eventIn SFBool set_boolean eventOut SFBool true_changed eventOut SFBool false_changed }, DEF TimeFilter Script { url "javascript: function set_boolean( bool, timeStamp ) { eventTime = timeStamp; }" eventIn SFBool set_boolean eventOut SFTime eventTime } ] } ROUTE Touch.isActive TO Filter.set_boolean ROUTE Filter.true_changed TO TimeFilter.set_boolean ROUTE TimeFilter.eventTime TO Audio.set_startTime ROUTE Touch.touchTime TO Audio.set_stopTime